#This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
#If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
from machine import Pin
from machine import PWM
from time import sleep_ms,sleep
#sleep(17)
class BUZZER:
    def __init__(self,sig_pin):
        self.pwm = PWM(Pin(sig_pin,Pin.OUT))
    #define funtion for playing
    def play(self,melodies,wait,duty):
            for note in melodies:
                print("[SWE]","Played:{}".format(note))
                if note:
                    self.pwm.freq(note)
                self.pwm.duty(duty)
                sleep_ms(wait)
            self.pwm.duty(0)
#C
L = [0, 131, 147, 165, 175, 196, 211, 248]
M = [0, 262, 294, 330, 350, 393, 441, 495]
H = [0, 525, 589, 661, 700, 786, 882, 990]

#CCCCCCCCCC
#谱子
songP = [
    M[3],L[5],M[1],M[3],M[5],M[3],M[5],M[7],
    H[1],M[6],M[5],M[4],M[3],M[2],
    M[1],M[3],M[2],M[1],
    M[1],L[7],
    M[0],M[0],L[5],L[6],    
    M[1],L[3],M[1],M[2],M[3],M[5],M[6],M[5],M[5],M[3],M[2],
    M[1],M[1],M[2],M[3],M[3],M[3],M[0],M[1],M[1],
    M[6],M[6],M[7],H[1],H[1],M[5],M[3],M[3],M[3],M[3],
    M[2],M[1],L[6],L[6],M[3],M[2],M[2],M[0],L[5],L[6],
    M[1],L[3],M[1],M[2],M[3],M[5],M[6],M[5],M[5],M[3],M[2],
    M[1],M[1],M[2],M[3],M[3],M[3],M[0],M[1],M[1],
    M[6],M[6],M[7],H[1],M[5],M[3],M[1],M[1],M[1],M[1],
    M[4],M[3],M[2],M[2],M[1],M[1],M[0],H[3],H[2],
    H[1],H[1],H[1],H[3],H[6],H[5],H[5],M[0],H[3],H[2],
    H[1],H[1],H[1],H[2],H[4],H[3],H[3],M[0],H[3],H[2],
    H[1],H[1],H[3],H[2],H[1],M[5],M[5],M[6],H[1],M[6],H[3],
    H[3],H[2],H[1],M[6],H[3],H[2],H[1],H[2],H[2],M[0],H[3],H[2],
    H[1],H[1],H[1],H[3],H[6],H[5],H[5],M[0],H[6],H[5],
    H[4],H[3],H[2],H[2],H[5],H[4],H[3],M[0],H[2],H[3],
    H[1],H[1],H[1],H[3],H[6],H[6],M[0],H[5],H[3],
    H[1],M[6],M[5],H[1],H[1],H[1],H[1],
    M[0],M[0],M[0],M[0],H[5],H[6],
    M[1],L[3],M[1],M[2],M[3],M[5],M[6],M[5],M[5],M[3],M[2],
    M[1],M[1],M[2],M[3],M[3],M[3],M[0],M[1],M[1],
    M[6],M[6],M[7],H[1],M[5],M[3],M[1],M[1],M[1],M[1],
    M[4],M[3],M[2],M[2],M[1],M[1],
    M[1],M[0],M[0],H[0],
    M[1],M[2],M[2],M[2],M[2],M[3],M[3],M[3],M[3],M[2],M[2],M[2],M[2],M[1],M[1],L[6],
    M[1],M[2],M[2],M[2],M[2],M[3],M[3],M[3],M[3],M[5],M[5],M[5],M[5],M[3],M[2],M[3],
    M[1],M[2],M[2],M[2],M[2],M[3],M[3],M[3],M[3],M[2],M[2],M[2],M[2],M[3],M[2],M[1],
    L[6],L[6],L[6],L[7],L[7],L[7],M[1],M[1],M[2],M[2],M[3],M[3],M[4],M[4],
    M[3],M[2],M[3],L[6],M[3],M[2],M[3],L[6],M[3],M[2],M[3],M[6],M[3],M[2],M[3],#bE
    M[2],M[1],M[2],L[5],M[2],M[1],M[2],L[5],M[2],M[1],M[2],M[5],M[2],M[1],M[2],#bE
    M[3],M[2],M[3],L[6],M[3],M[2],M[3],L[6],M[4],M[3],M[4],L[6],M[4],M[3],M[2],M[1],#bE
    M[2],M[2],M[3],M[0],L[5],L[6],
    M[1],L[3],M[1],M[2],M[3],M[5],M[6],M[5],M[5],M[3],M[2],
    M[1],M[1],M[2],M[3],M[3],M[3],M[0],M[1],M[1],
    M[6],M[6],M[7],H[1],M[5],M[3],M[1],M[1],M[1],M[1],
    M[4],M[3],M[2],M[2],M[1],M[1],M[1],M[0],M[5],H[3],H[2],
    H[1],H[1],H[1],H[1],H[3],H[6],H[5],H[5],M[0],M[5],H[3],H[2],
    H[1],H[1],H[1],H[2],H[4],H[3],H[3],M[0],H[3],H[2],
    H[1],H[1],H[1],H[3],H[2],H[1],M[5],M[6],H[1],M[6],H[3],
    H[3],H[2],H[1],M[6],H[5],H[5],H[5],H[3],H[3],H[2],M[0],H[3],H[2],
    H[1],H[1],H[1],H[3],H[6],H[5],H[5],M[0],H[6],H[5],#Next page
    H[4],H[3],H[2],H[2],H[5],H[4],H[3],M[0],H[2],H[3],
    H[1],H[1],H[1],H[3],H[6],H[6],M[0],M[5],H[5],H[3],
    H[1],M[6],M[5],H[1],H[2],
    H[2],H[1],H[1],0,M[0],H[3],H[2],
    H[1],H[1],H[1],H[3],H[6],H[6],H[5],M[0],H[3],H[2],
    H[1],H[1],H[1],H[2],H[4],H[4],H[3],M[0],H[3],H[2],
    H[1],H[1],H[3],H[2],H[1],M[5],M[6],H[1],M[6],H[3],
    H[3],H[2],H[1],M[6],H[5],H[5],H[5],H[3],H[3],H[2],M[0],H[3],H[2],
    H[1],H[1],H[2],H[1],H[6],H[5],H[5],H[5],H[1],H[7],#ERROR-IGNORED
    H[6],H[5],H[5],H[4],H[3],H[3],M[0],H[2],H[3],
    H[1],H[1],H[1],H[3],H[6],H[6],M[0],H[5],H[3],
    H[1],M[6],M[5],H[1],H[2],
    H[2],H[1],H[1],0,M[0],
    M[0],M[0],M[0],M[0],L[5],L[6],
    M[1],L[3],M[1],M[2],M[3],M[5],M[6],M[5],M[5],M[3],M[2],
    M[1],M[1],M[2],M[3],M[3],M[3],M[0],M[1],M[1],
    M[6],M[6],M[7],H[1],M[5],M[3],M[1],M[1],M[1],M[1],
    M[4],M[3],M[2],M[2],M[1],M[1],M[0],
    ]
#Restore
buzzer = BUZZER(6)

print("Do not fear,I'm here with you")
buzzer.play(songP,406,650)
print("Thanks!")
